package com.hongning.railway.ui.main.fragments.college.itemviewModel;

import android.databinding.ObservableField;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResExamCompleteBean;
import com.hongning.railway.ui.main.fragments.college.exam.CheckAnswerFragment;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class ExamCopleteItemViewModel extends MultiItemViewModel {
    public ObservableField<Integer> statu = new ObservableField<>();
    public ObservableField<ResExamCompleteBean> data = new ObservableField<>();
    public ObservableField<String> wrong = new ObservableField<>();
    public ObservableField<String> right = new ObservableField<>();
    public ObservableField<String> numperson = new ObservableField<>();

    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString(Constant.EXTRA_DATA,data.get().getExamId()+"");
            bundle.putInt(Constant.EXTRA_INT,data.get().getExamType());
            bundle.putString(Constant.EXTRA_STRING,data.get().getId()+"");
            viewModel.startContainerActivity(CheckAnswerFragment.class.getCanonicalName(),bundle);
        }
    });
    public ExamCopleteItemViewModel(@NonNull BaseViewModel viewModel,ResExamCompleteBean resExamCompleteBean) {
        super(viewModel);
        right.set(resExamCompleteBean.getResult()+"题");
        int wrongnum = resExamCompleteBean.getTotalTopicNum()-resExamCompleteBean.getResult();
        wrong.set(wrongnum+"题");
        numperson.set(String.format("%d人已完成",resExamCompleteBean.getPronum()));
        data.set(resExamCompleteBean);
        if (resExamCompleteBean.getExamType()==1){
            statu.set(R.mipmap.icon_exam_vip);
        }else {
            statu.set(R.mipmap.icon_exam_week);
        }
    }
}
